home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / common / headers.h / piutilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  22.8 KB  |  764 lines

  1. /*
  2.     File:  PIUtilities.h
  3.     
  4.     Copyright (c) 1993-6, Adobe Systems Incorporated.
  5.     All rights reserved.
  6.  
  7.     The routines in this module provide a collection of utilities for accessing
  8.      the plug-in callback procedures and performing other useful tasks within
  9.       plug-ins.
  10. */
  11.  
  12. #ifndef __PIUtilities_H__
  13. #define __PIUtilities_H__
  14.  
  15. #include <stddef.h>
  16. #include <Types.h>
  17. #include "PITypes.h"
  18. #include "PIGeneral.h"
  19. #include "PIActions.h"
  20. #include "PIAbout.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. #if Macintosh
  25. #include "DialogUtilities.h"
  26. #include "LowMem.h"
  27. #define PISetRect    SetRect
  28. #else
  29. #include <stdlib.h>
  30.  
  31. #include <winver.h>
  32. #include "WinUtilities.h"
  33. #include "WinDialogUtils.h"
  34. Fixed FixRatio(short numer, short denom);
  35. #endif
  36.  
  37. /*****************************************************************************/
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. /*****************************************************************************/
  44. /* Map to resource strings */
  45.  
  46. // Some of these are generic.  Override if you need to in your .h files.
  47.  
  48. #define ResourceID        16000
  49. #define AboutID            ResourceID
  50. #define uiID            ResourceID+1
  51. #define AlertID            16990
  52. #define kBadNumberID    AlertID
  53. #define kBadDoubleID    kBadNumberID+1
  54. #define kNeedVers        kBadDoubleID+1
  55. #define kWrongHost        kNeedVers+1
  56. #define StringResource    'STR '
  57.  
  58. /*****************************************************************************/
  59. /* Gets the platform window ptr.             */
  60.  
  61. Handle HostGetPlatformWindowPtr (AboutRecordPtr aboutPtr);
  62.  
  63. #define PIPlatform()    \
  64.     HostGetPlatformWindowPtr((AboutRecordPtr)gStuff)
  65.  
  66. /*****************************************************************************/
  67.  
  68. /* The following routines provide shells around the buffer procs routines.
  69.    These routines allow us to allocate buffers from Photoshop's memory
  70.    without first telling Photoshop about it in the bufferSpace or maxSpace
  71.    parameter in the interface record.  This can be useful when we need
  72.    different sized buffers at different times. */
  73.  
  74. /* Are the buffer procs even available?  If not, the plug-in will have to
  75.    put up a warning dialog to indicate that it requires Photoshop 2.5 or
  76.    will have to work around this using the old memory management techniques
  77.    documented in earlier versions of the plug-in kit.  tooNew is set if the
  78.    procs version is newer than the plug-in.  The buffer procs version number
  79.    is unlikely to change, but it is wise to test it anyway.  If tooNew is
  80.    null, it will be ignored. */
  81.  
  82. Boolean HostBufferProcsAvailable (BufferProcs *procs, Boolean *tooNew);
  83.  
  84. /* The following dialog takes care of putting up the warning if the appropriate
  85.    version of the buffer procs is not available. */
  86.  
  87. Boolean WarnHostBufferProcsAvailable (BufferProcs *procs, Handle hDllInstance);
  88.  
  89. /* How much space is available for buffers?  This space may be fragmented. */
  90.  
  91. int32 HostBufferSpace (BufferProcs *procs); 
  92.  
  93. /* Allocate a buffer of the appropriate size setting bufferID to the ID
  94.    for the buffer.  If an error occurs, the error code will be returned
  95.    and bufferID will be set to zero. */
  96.  
  97. OSErr HostAllocateBuffer (BufferProcs *procs, int32 size, BufferID *bufferID);
  98.  
  99. /* Free the buffer with the given ID. */
  100.  
  101. void HostFreeBuffer (BufferProcs *procs, BufferID bufferID);
  102.  
  103. /* Lock the buffer and return a pointer to its contents. */
  104.  
  105. Ptr HostLockBuffer (BufferProcs *procs, BufferID bufferID, Boolean moveHigh);
  106.  
  107. /* Unlock the buffer.  Lock and unlock calls manipulate a counter, so they
  108.    must balance perfectly. */
  109.  
  110. void HostUnlockBuffer (BufferProcs *procs, BufferID bufferID);
  111.  
  112. /* The following routine allocates a buffer which is as tall as possible.  It
  113.    takes as parameters, the desired rowBytes, the minimum height, the
  114.    maximum height, and the fraction of the available buffer space to use
  115.    expressed as 1/numBuffers.  It sets the actual height and bufferID
  116.    parameters if successful. */
  117.  
  118. OSErr HostAllocateStripBuffer (BufferProcs *procs,
  119.                                int32 rowBytes,
  120.                                int16 minHeight,
  121.                                int16 maxHeight,
  122.                                int16 numBuffers,
  123.                                int16 *actualHeight,
  124.                                BufferID *bufferID);
  125.  
  126. /*****************************************************************************/
  127.  
  128. /*****************************************************************************/
  129. /* Check for the advance state procedure and warn if not present.             
  130.    The macros assume that gStuff is defined somewhere as a pointer
  131.    to the current interface record. */
  132.  
  133. Boolean HostAdvanceStateAvailable (AdvanceStateProc proc);
  134.  
  135. Boolean WarnHostAdvanceStateAvailable (AdvanceStateProc proc, Handle hDllInstance);
  136.    
  137. #define AdvanceStateAvailable() \
  138.     HostAdvanceStateAvailable (gStuff->advanceState)
  139.  
  140. #define WarnAdvanceStateAvailable() \
  141.     WarnHostAdvanceStateAvailable (gStuff->advanceState, hDllInstance)
  142.     
  143. #define AdvanceState() \
  144.     (*(gStuff->advanceState)) ()
  145.  
  146. /*****************************************************************************/
  147.  
  148. /* Here are the routines for the buffer suite. */
  149.  
  150. #define BufferProcsAvailable(tooNew) \
  151.     HostBufferProcsAvailable (gStuff->bufferProcs, tooNew)
  152.  
  153. #define WarnBufferProcsAvailable() \
  154.     WarnHostBufferProcsAvailable (gStuff->bufferProcs, hDllInstance)
  155.  
  156. #define BufferSpace() HostBufferSpace (gStuff->bufferProcs)
  157.  
  158. #define AllocateBuffer(size,bufferID) \
  159.     HostAllocateBuffer (gStuff->bufferProcs, size, bufferID)
  160.  
  161. #define FreeBuffer(bufferID) \
  162.     HostFreeBuffer (gStuff->bufferProcs, bufferID)
  163.  
  164. #define LockBuffer(bufferID,moveHigh) \
  165.     HostLockBuffer (gStuff->bufferProcs, bufferID, moveHigh)
  166.  
  167. #define UnlockBuffer(bufferID) \
  168.     HostUnlockBuffer (gStuff->bufferProcs, bufferID)
  169.  
  170. #define AllocateStripBuffer(rowBytes,minHeight,maxHeight,numBuffers,actualHeight,bufferID) \
  171.     HostAllocateStripBuffer (gStuff->bufferProcs,\
  172.                              rowBytes,\
  173.                              minHeight,\
  174.                              maxHeight,\
  175.                              numBuffers,\
  176.                              actualHeight,\
  177.                              bufferID)
  178.  
  179. /****************************************************************************
  180.  * Similarly assuming gStuff to be defined, we define macros for testing
  181.  * for abort and for updating the progress bar.
  182.  */
  183.  
  184. #define TestAbort() ((*gStuff->abortProc) ())
  185.  
  186. #define UpdateProgress(done,total) ((*gStuff->progressProc) (done, total))
  187.  
  188. /*****************************************************************************/
  189.  
  190. /* Here is a corresponding set of routines and macros for the pseudo-resource
  191.  * callbacks.
  192.  * These macros also make the additional assumption that hDllInstance is
  193.  * defined as a global variable (NULL on Mac, value for Windows).
  194.  */
  195.  
  196. Boolean HostResourceProcsAvailable (ResourceProcs *procs, Boolean *tooNew);
  197.  
  198. Boolean WarnHostResourceProcsAvailable (ResourceProcs *procs, Handle hDllInstance);
  199.  
  200. int16 HostCountPIResources (ResourceProcs *procs, ResType type);
  201.  
  202. Handle HostGetPIResource (ResourceProcs *procs, ResType type, int16 index);
  203.  
  204. void HostDeletePIResource (ResourceProcs *procs, ResType type, int16 index);
  205.  
  206. OSErr HostAddPIResource (ResourceProcs *procs, ResType type, Handle data);
  207.  
  208. Ptr HostGetResource (Handle hDllInstance, ResType type, int32 index, int32 *size);
  209.  
  210. // int32 resource to 4-chars
  211. void PIType2Char (const ResType type, char *name);
  212.  
  213. // 4-chars to int32 resource
  214. ResType PIChar2Type (char *name);
  215.  
  216. void PIReleaseResource(Ptr p);
  217.  
  218. void HostGetString (Handle hDllInstance, Str255 s, int32 index);
  219.  
  220. #define ResourceProcsAvailable(tooNew)                                        \
  221.     HostResourceProcsAvailable (gStuff->resourceProcs, tooNew)
  222.     
  223. #define WarnResourceProcsAvailable()                                        \
  224.     WarnHostResourceProcsAvailable (gStuff->resourceProcs, hDllInstance)
  225.     
  226. #define CountPIResources(type)                                                \
  227.     HostCountPIResources (gStuff->resourceProcs, type)
  228.     
  229. #define GetPIResource(type,index)                                            \
  230.     HostGetPIResource (gStuff->resourceProcs, type, index)
  231.     
  232. #define DeletePIResource(type,index)                                        \
  233.     HostDeletePIResource (gStuff->resourceProcs, type, index)
  234.     
  235. #define AddPIResource(type,data)                                            \
  236.     HostAddPIResource (gStuff->resourceProcs, type, data)
  237.  
  238. #define PIGetResource(type, index, size)                                    \
  239.     HostGetResource(hDllInstance, type, index, size)
  240.  
  241. #define PIGetString(s, index)                                                \
  242.     HostGetString(hDllInstance, s, index)
  243.  
  244. /*****************************************************************************/
  245.  
  246. /* And a set for the handle routines. */
  247.  
  248. Boolean HostHandleProcsAvailable (HandleProcs *procs, Boolean *tooNew);
  249.  
  250. Boolean WarnHostHandleProcsAvailable (HandleProcs *procs, Handle hDllInstance);
  251.  
  252. Handle HostNewHandle (HandleProcs *procs, int32 size);
  253.  
  254. void HostDisposeHandle (HandleProcs *procs, Handle h);
  255.  
  256. void HostBlockMove (Ptr p1, Ptr p2, const int32 amount);
  257.  
  258. void HostCopy (void *s1, const void *s2, const int32 amount);
  259.  
  260. int32 HostGetHandleSize (HandleProcs *procs, Handle h);
  261.  
  262. OSErr HostSetHandleSize (HandleProcs *procs, Handle h, int32 newSize);
  263.  
  264. Ptr HostLockHandle (HandleProcs *procs, Handle h, Boolean moveHigh);
  265.  
  266. void HostUnlockHandle (HandleProcs *procs, Handle h);
  267.  
  268. void HostHandle2String (HandleProcs *procs, Handle h, Str255 s);
  269.  
  270. Handle HostString2Handle (HandleProcs *procs, Str255 s);
  271.  
  272. Handle HostHandleCat (HandleProcs *procs, Handle h1, Handle h2);
  273.  
  274. int16 HostMatch(char *s1, const char *s2, Boolean ignoreCase);
  275.  
  276. int16 HostStringMatch(Str255 s1, char *s2, Boolean ignoreCase);
  277.  
  278. char UpperToLower(const char c1);
  279.  
  280. int16 HostStringCat(char *s1, const char *s2);
  281.  
  282. #define HandleProcsAvailable(tooNew)                                        \
  283.     HostHandleProcsAvailable (gStuff->handleProcs, tooNew)
  284.     
  285. #define WarnHandleProcsAvailable()                                            \
  286.     WarnHostHandleProcsAvailable (gStuff->handleProcs, hDllInstance);
  287.     
  288. #define PINewHandle(size)                                                    \
  289.     HostNewHandle (gStuff->handleProcs, size)
  290.     
  291. #define PIDisposeHandle(h)                                                    \
  292.     HostDisposeHandle (gStuff->handleProcs, h)
  293.     
  294. #define PIGetHandleSize(h)                                                    \
  295.     HostGetHandleSize (gStuff->handleProcs, h)
  296.     
  297. #define PISetHandleSize(h,size)                                                \
  298.     HostSetHandleSize (gStuff->handleProcs, h, size)
  299.     
  300. #define PILockHandle(h,moveHigh)                                            \
  301.     HostLockHandle (gStuff->handleProcs, h, moveHigh)
  302.     
  303. #define PIUnlockHandle(h)                                                    \
  304.     HostUnlockHandle (gStuff->handleProcs, h)
  305.  
  306. #define PIString2Handle(s)                                                    \
  307.     HostString2Handle (gStuff->handleProcs, s)
  308.     
  309. #define PIHandle2String(h, s)                                                \
  310.     HostHandle2String (gStuff->handleProcs, h, s)
  311.  
  312. #define PIHandleCat(h1, h2)                                                    \
  313.     HostHandleCat(gStuff->handleProcs, h1, h2)
  314.     
  315. #define PICloneHandle(h)                                                    \
  316.     HostHandleCat(gStuff->handleProcs, NULL, h)
  317.     
  318. #define PICopy(s1, s2, size)                                                \
  319.     HostCopy(s1, s2, size)
  320.  
  321. #define PIBlockMove(p1, p2, size)                                            \
  322.     HostBlockMove (p1, p2, size)
  323.     
  324. #define noMatch    -1
  325. #define gotMatch 0
  326. // any other number is exact match at offset #
  327.  
  328. #define PIMatch(s1, s2)                                                        \
  329.     HostMatch(s1, s2, true)
  330.     
  331. #define PISMatch(s1, s2)                                                    \
  332.     HostStringMatch(s1, s2, true)
  333.  
  334. #define PIStringCat(s1, s2)                                                    \
  335.     HostStringCat(s1, s2)
  336.  
  337. /*****************************************************************************/
  338.  
  339. /* Routines for Display Pixels procs */
  340.  
  341. Boolean HostDisplayPixelsAvailable (DisplayPixelsProc proc);
  342.  
  343. Boolean WarnHostDisplayPixelsAvailable (DisplayPixelsProc proc,
  344.                                         Handle hDllInstance);
  345.  
  346. #define DisplayPixelsAvailable() \
  347.     HostDisplayPixelsAvailable (gStuff->displayPixels)
  348.  
  349. #define    WarnDisplayPixelsAvailable() \
  350.     WarnHostDisplayPixelsAvailable (gStuff->displayPixels, hDllInstance)
  351.  
  352. /*****************************************************************************/
  353.  
  354. /* Routines for Property procs */
  355.  
  356. Boolean HostPropertyAvailable (PropertyProcs *procs, Boolean *tooNew);
  357.  
  358. Boolean WarnHostPropertyAvailable (PropertyProcs *procs, Handle hDllInstance);
  359.  
  360. #define PropertyAvailable() \
  361.     HostPropertyAvailable (gStuff->propertyProcs)
  362.  
  363. #define WarnPropertyAvailable()    \
  364.     WarnHostPropertyAvailable (gStuff->propertyProcs, hDllInstance)
  365.  
  366. #define PIGetProp        gStuff->propertyProcs->getPropertyProc
  367. #define PISetProp        gStuff->propertyProcs->setPropertyProc
  368.  
  369. #define GetSimple(key, simple)    \
  370.     PIGetProp('8BIM', key, 0, simple, nil)
  371.  
  372. #define PutSimple(key, simple)  \
  373.     PISetProp('8BIM', key, 0, simple, nil)
  374.     
  375. #define GetComplex(key, index, complex)    \
  376.     PIGetProp('8BIM', key, index, 0, complex)
  377.     
  378. #define PutComplex(key, index, complex)    \
  379.     PISetProp('8BIM', key, index, 0, complex)
  380.     
  381. /*****************************************************************************/
  382.  
  383. /* Routines for the Channel Port procs */
  384.     
  385. Boolean HostChannelPortAvailable (ChannelPortProcs *procs, Boolean *tooNew);
  386.  
  387. Boolean WarnHostChannelPortAvailable (ChannelPortProcs *procs, Handle hDllInstance);
  388.  
  389. #define ChannelPort \
  390.     (gStuff->channelPortProcs)
  391.     
  392. #define ReadPixels \
  393.     (ChannelPort->readPixelsProc)
  394.  
  395. #define WritePixels \
  396.     (ChannelPort->writeBasePixelsProc)
  397.  
  398. #define ReadFromWritePort \
  399.     (ChannelPort->readPortForWritePortProc)
  400.  
  401. #define ChannelPortAvailable(tooNew) \
  402.     HostChannelPortAvailable (ChannelPort, tooNew)
  403.  
  404. #define WarnChannelPortAvailable() \
  405.     WarnHostChannelPortAvailable (ChannelPort, hDllInstance)
  406.     
  407. /*****************************************************************************/
  408.  
  409. short HostReportError(Str255 s1, Str255 s2);
  410.  
  411. #define PIReportError(errString) \
  412.     HostReportError(*(gStuff->errorString), errString)
  413.  
  414. /*****************************************************************************/
  415.  
  416. /* Here are the routines for the scripting system */
  417.     
  418. #define NULLID                0 // for ID routines needing null terminator
  419.  
  420. Boolean HostDescriptorAvailable (PIDescriptorParameters *procs, Boolean *tooNew);
  421.  
  422. Boolean WarnHostDescriptorAvailable (PIDescriptorParameters *procs, Handle hDllInstance);
  423.  
  424. /* Closes read descriptor and disposes handle. */
  425. OSErr    HostCloseReader (PIDescriptorParameters *procs, HandleProcs *hProcs, PIReadDescriptor *token);
  426.  
  427. /* Closes write descriptor.  Disposes old handle, if present, and sets
  428.    recordInfo to plugInDialogOptional. */
  429. OSErr    HostCloseWriter (PIDescriptorParameters *procs,
  430.                          HandleProcs *hProcs,
  431.                          PIWriteDescriptor *token);
  432.  
  433. /* Puts an object and disposes its handle, returning any error. */
  434. OSErr HostPutObj (PIDescriptorParameters *procs, HandleProcs *hProcs, 
  435.                   PIWriteDescriptor desc, DescriptorKeyID key, DescriptorTypeID type,
  436.                   PIDescriptorHandle *h);
  437.                   
  438. /* Returns whether playInfo is plugInDialogDisplay, meaning to absolutely pop
  439.    the plug-in dialog. */
  440. Boolean HostPlayDialog (PIDescriptorParameters *procs);
  441.  
  442. #define DescParams     gStuff->descriptorParameters
  443.  
  444. #define Reader         DescParams->readDescriptorProcs
  445.  
  446. #define Writer         DescParams->writeDescriptorProcs
  447.  
  448. #define PlayInfo    DescParams->playInfo
  449.  
  450. #define RecordInfo    DescParams->recordInfo
  451.  
  452. #define    PlayDialog() \
  453.     HostPlayDialog (DescParams)
  454.  
  455. #define DescriptorAvailable() \
  456.     HostDescriptorAvailable(DescParams, false)
  457.  
  458. #define WarnDescriptorAvailable() \
  459.     WarnHostDescriptorAvailable(DescParams, hDllInstance)
  460.  
  461. #define OpenReadDesc(desc, array) \
  462.     Reader->openReadDescriptorProc(desc, array)
  463.  
  464. #define    OpenReader(array) \
  465.     OpenReadDesc(DescParams->descriptor, array)
  466.     
  467. #define CloseReadDesc(token) \
  468.     Reader->closeReadDescriptorProc(token)
  469.  
  470. #define CloseReader(token) \
  471.     HostCloseReader(DescParams, gStuff->handleProcs, token)
  472.     
  473. #define OpenWriter() \
  474.     Writer->openWriteDescriptorProc()
  475.  
  476. #define CloseWriteDesc(token, handle) \
  477.     Writer->closeWriteDescriptorProc(token, handle)
  478.  
  479. #define CloseWriter(token) \
  480.     HostCloseWriter(DescParams, gStuff->handleProcs, token)
  481.  
  482. #define PIGetKey(token, key, type, flags) \
  483.     Reader->getKeyProc(token, key, type, flags)
  484.     
  485. #define PIGetEnum(token, value)    \
  486.     Reader->getEnumeratedProc(token, value)
  487.                 
  488. #define PIPutEnum(token, key, type, value) \
  489.     Writer->putEnumeratedProc(token, key, type, value)
  490.     
  491. #define PIGetInt(token, value) \
  492.     Reader->getIntegerProc(token, value)
  493.  
  494. #define PIGetPinInt(token, min, max, value) \
  495.     Reader->getPinnedIntegerProc(token, min, max, value)
  496.  
  497. #define PIPutInt(token, key, value) \
  498.     Writer->putIntegerProc(token, key, value)
  499.     
  500. #define PIGetFloat(token, value) \
  501.     Reader->getFloatProc(token, value)
  502.     
  503. #define PIGetPinFloat(token, min, max, value) \
  504.     Reader->getPinnedFloatProc(token, min, max, value)
  505.  
  506. #define PIPutFloat(token, key, value) \
  507.     Writer->putFloatProc(token, key, value)
  508.     
  509. #define PIGetUnitFloat(token, unit, value) \
  510.     Reader->getUnitFloatProc(token, unit, value)
  511.  
  512. #define PIGetPinUnitFloat(token, min, max, unit, value) \
  513.     Reader->getPinnedUnitFloatProc(token, min, max, unit, value)
  514.  
  515. #define PIPutUnitFloat(token, key, unit, value) \
  516.     Writer->putUnitFloatProc(token, key, unit, value)
  517.     
  518. #define PIGetBool(token, value) \
  519.     Reader->getBooleanProc(token, value)
  520.  
  521. #define PIPutBool(token, key, value) \
  522.     Writer->putBooleanProc(token, key, value)
  523.  
  524. #define PIGetText(token, value) \
  525.     Reader->getTextProc(token, value)
  526.     
  527. #define PIPutText(token, key, value) \
  528.     Writer->putTextProc(token, key, value)
  529.     
  530. #define PIGetAlias(token, value) \
  531.     Reader->getAliasProc(token, value)
  532.     
  533. #define PIPutAlias(token, key, value) \
  534.     Writer->putAliasProc(token, key, value)
  535.  
  536. #define PIGetEnum(token, value) \
  537.     Reader->getEnumeratedProc(token, value)
  538.  
  539. #define PIPutEnum(token, key, type, value) \
  540.     Writer->putEnumeratedProc(token, key, type, value)
  541.  
  542. #define PIGetClass(token, value) \
  543.     Reader->getClassProc(token, value)
  544.     
  545. #define PIPutClass(token, key, value) \
  546.     Writer->putClassProc(token, key, value)
  547.     
  548. #define PIGetRef(token, value) \
  549.     Reader->getSimpleReferenceProc(token,value)
  550.     
  551. #define PIPutRef(token, key, value) \
  552.     Writer->putSimpleReferenceProc(token, key, value)
  553.     
  554. #define PIGetObj(token, type, value) \
  555.     Reader->getObjectProc(token, type, value)
  556.  
  557. #define PIPutObj(token, key, type, value) \
  558.     HostPutObj(DescParams, gStuff->handleProcs, token, key, type, value)
  559.  
  560. #define PIPutObjProc(token, key, type, value) \
  561.     Writer->putObjectProc(token, key, type, value)
  562.     
  563. #define PIGetCount(token, value) \
  564.     Reader->getCountProc(token, value)
  565.     
  566. #define PIPutCount(token, key, value) \
  567.     Writer->putCountProc(token, key, value)
  568.     
  569. #define PIGetStr(token, value) \
  570.     Reader->getStringProc(token, value)
  571.     
  572. #define PIPutStr(token, key, value) \
  573.     Writer->putStringProc(token, key, value)
  574.  
  575. /*****************************************************************************/
  576.  
  577. /* The following macros assume that gStuff is defined somewhere as a pointer
  578.    to the current interface record. */
  579.    
  580. Boolean HostColorServicesAvailable (ColorServicesProc proc);
  581.  
  582. Boolean WarnHostColorServicesAvailable (ColorServicesProc proc, Handle hDLLinstance);
  583.  
  584. /* Sets a color array from four int16 colors */
  585. void CSSetColor (int16 *color, int16 color1, int16 color2, int16 color3, int16 color4);
  586.  
  587. /* Copies one color2 array to color1 */
  588. void CSCopyColor (int16 *color1, int16 *color2);
  589.  
  590. OSErr HostCSConvertColor (ColorServicesProc proc,
  591.                          int16 sourceSpace,
  592.                          int16 resultSpace,
  593.                          int16 *color);
  594.  
  595. /* Returns number of expected planes for imageMode */
  596. int16 CSPlanesFromMode (int16 imageMode, int16 currPlanes);
  597.  
  598. /* Maps imageMode to color services space.  Returns -1 if notSupported. */
  599. int16 CSModeToSpace (int16 imageMode);
  600.  
  601. #define ColorServicesAvailable() \
  602.     HostColorServicesAvailable (gStuff->colorServices)
  603.  
  604. #define WarnColorServicesAvailable() \
  605.     WarnHostColorServicesAvailable (gStuff->colorServices, hDllInstance)
  606.     
  607. #define ColorServices(info) \
  608.     (*(gStuff->colorServices)) (info)
  609.  
  610. /* Converts a color array from sourceSpace to targetSpace, returning in array */
  611. #define CSConvertColor(source, result, color) \
  612.     HostCSConvertColor (gStuff->colorServices, source, result, color)
  613.  
  614. /*****************************************************************************/
  615. /* Gestalt-like OS functions */
  616.  
  617. typedef struct OSInfo
  618. {
  619.     ResType        signature;
  620.     unsigned8    majorVersion;
  621.     unsigned8    minorVersion;
  622.     unsigned8    subVersion;
  623.     unsigned8    stage;
  624.     unsigned8    stageVersion;
  625.     unsigned8    os;
  626. } OSInfo, *POSInfo, **HOSInfo;
  627.  
  628. enum
  629. { // "stage" will be one of these:
  630.     OSStageDevelopment,
  631.     OSStageAlpha,
  632.     OSStageBeta,
  633.     OSStageRelease
  634. };
  635.  
  636. enum
  637. { // "os" will be one of these:
  638.     OSMacOS6 = 1,
  639.     OSMacOS7,
  640.     OSMacOS8,
  641.     OSWinNT = 10,
  642.     OSWin16,
  643.     OSWin32
  644. };
  645.  
  646. #define OSMacOS1    OSMacOS6
  647. #define OSMacOSEnd    OSMacOS8
  648.  
  649. #define OSWin1        OSWinNT
  650. #define OSWinEnd    OSWin32
  651.  
  652. // Macintosh ResTypes and Windows file names for popular Adobe apps
  653. #define rtAfterEffects        'FXTC'
  654. #define fnAfterEffects        "Adobe After Effects"
  655.  
  656. #define rtIllustrator        'ART5'
  657. #define fnIllustrator        "Adobe Illustrator"
  658.  
  659. #define rtPageMaker5        'ALD5'
  660. #define fnPageMaker5        "PM5"
  661.  
  662. #define rtPageMaker6        'ALD6'
  663. #define fnPageMaker6        "PM6"
  664.  
  665. #define rtPageMaker65        'AD65'
  666. #define fnPageMaker65        "PM65"
  667.  
  668. #define rtPhotoDeluxe        'PHUT'
  669. #define fnPhotoDeluxe        "PhotoDeluxe"
  670.  
  671. #define rtPhotoshop            kPhotoshopSignature // '8BIM'
  672. #define fnPhotoshop            "Photoshp"
  673.  
  674. #define rtPremiere            'PrMr'
  675. #define fnPremiere            "Adobe Premiere"
  676.  
  677. void GetOSInfo (HandleProcs *procs, OSInfo *osInfo);
  678.  
  679. unsigned32 AppMatch (HandleProcs *procs, ResType *type);
  680.  
  681. unsigned32 HostHostIsApp (HandleProcs *procs, const ResType type);
  682.  
  683. unsigned8 MapSystem (const unsigned32 os);
  684.  
  685. unsigned8 MapStage (const unsigned32 stageMask, const unsigned32 stage);
  686.  
  687. unsigned32 MapSignature (char *s1);
  688.  
  689. Boolean        IsWindows (const unsigned32 flag);
  690.  
  691. Boolean        IsMacOS (const unsigned32 flag);
  692.  
  693. #define HostIsApp(type) \
  694.     HostHostIsApp (gStuff->handleProcs, type)
  695.  
  696. #define HostIsAfterEffects() \
  697.     HostIsApp(rtAfterEffects)
  698.     
  699. #define HostIsIllustrator() \
  700.     HostIsApp(rtIllustrator)
  701.     
  702. #define HostIsPageMaker() \
  703.     HostIsApp (rtPageMaker5)
  704.     
  705. #define HostIsPhotoDeluxe() \
  706.     HostIsApp (rtPhotoDeluxe)
  707.  
  708. #define HostIsPhotoshop() \
  709.     HostIsApp (rtPhotoshop)
  710.  
  711. #define HostIsPremiere() \
  712.     HostIsApp (rtPremiere)
  713.                 
  714. /*****************************************************************************/
  715. /* String and Number functions */
  716.  
  717. /* Convert a string to its long value */
  718. Boolean StringToNumber (Str255 s, long *value);
  719.  
  720. /* Append one string to a pascal string */
  721. void AppendString (Str255 s1, Str255 s2, short start, short length);
  722.  
  723. /* Add a character to a pascal string */
  724. void AppendCharToString (Str255 s1, const unsigned char c);
  725.  
  726. /* Change a double value to a string, with a minimal amount of 
  727.    decimal points (precision) */
  728. void DoubleToString (double value, Str255 s, short precision);
  729.  
  730. /* Takes source string and moves everything after a decimal to target,
  731.    removing extra from source */
  732. void DivideAtDecimal(Str255 s1, Str255 s2);
  733.  
  734. /* Faux version of Macintosh ParamText: Takes a string and replaces
  735.    occurences of "^0" with r1, "^1" with r2, and "^2" with r3. */
  736. void PIParamText(unsigned char *s, unsigned char *r1, unsigned char *r2, unsigned char *r3);
  737.  
  738. /* Raises a base to a power */
  739. double power (long base, short raise);
  740.  
  741. /* Multipliers to move long to fixed */
  742. #define kHard16                (1L << 16) /* 16.16 */
  743. #define kSoft16                kHard16 // use for "other" number systems
  744.  
  745. /* 16.16 (or other) -> double and double -> 16.16 (or other) */
  746. #define PIFixedToDouble(x, shift)    (x / (double) shift)
  747. #define PIDoubleToFixed(x, shift)    ((int32)(x * shift))
  748. #define Fixed16ToDouble(x)     (x / (double) 65536.0)
  749. #define DoubleToFixed16(x)     ((int32)(x * 65536))
  750.  
  751. /* 16.16 -> long and long -> 16.16 */
  752. #define long2fixed(value)    (value << 16)
  753. #define fixed2long(value)    (value >> 16)
  754.  
  755. /*****************************************************************************/
  756.  
  757. #ifdef __cplusplus
  758. } /* End of extern "C" block. */
  759. #endif
  760.  
  761. /*****************************************************************************/
  762.  
  763. #endif /* __PIUtilities__ */
  764.